﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE FUNCTION [dbo].[PU_Payed_PyIn] 
(
	@puId int, 
	@payId int
)
RETURNS money
AS
BEGIN
	DECLARE @sum money
	SET @sum = 0
	SELECT @sum = ISNULL(SUM(pii.SUM_RUB),0) FROM PAYMENT_IN_ITEM as pii
													WHERE (pii.PAYMENT_IN_ID = @payId AND pii.PRODUCT_UNIT_ID = @puId)
	
	RETURN @sum
END